package com.abe.libquick.base;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.text.TextUtils;

import androidx.lifecycle.ViewModelProvider;
import androidx.viewbinding.ViewBinding;

import com.abe.libcore.base.screen.j.AbeJActivity;

public abstract class BaseActivity<T extends ViewBinding> extends AbeJActivity {
    protected T binding;
    private AlertDialog loadDialog;

    protected abstract T getBinding();

    protected abstract void initContent();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = getBinding();
        setContentView(binding.getRoot());
        initContent();
    }

    @Override
    public Boolean isAutoZoom() {
        return false;
    }

    public void showLoadDialog(String msg) {
        if (!isAlive) return;
        if (loadDialog == null) loadDialog = new ProgressDialog(this);
        loadDialog.setMessage(TextUtils.isEmpty(msg) ? "Loading..." : msg);
        loadDialog.setCancelable(true);
        if (!loadDialog.isShowing()) {
            loadDialog.show();
        }
    }

    public void disLoadDialog() {
        if (!isAlive) return;
        if (loadDialog != null) loadDialog.dismiss();
    }

    public static class VMFactory extends ViewModelProvider.AndroidViewModelFactory {
        public VMFactory() {
            super(ApplicationHelper.application());
        }
    }
}